package com.elvt.server.controller;


import com.elvt.server.pojo.Position;
import com.elvt.server.service.IPositionService;
import com.elvt.server.utils.RespSult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 作者：elvt
 * @since 2022-05-21
 */
@RestController
@RequestMapping("system/basic/position")
public class PositionController {
    @Autowired
    private IPositionService iPositionService;
    @ApiOperation(value = "获取所有职位信息")
    @GetMapping
    public List<Position> findPosition(){
        return iPositionService.list();

    }
    @ApiOperation(value = "添加职位信息")
    @PostMapping
    public RespSult addPosition(@RequestBody Position position){
        if (StringUtils.isEmpty(position.getName()) ||position.getName().equals("")){
            return RespSult.error("输入的信息不能空");
        }
        if (iPositionService.save(position)) {
            return RespSult.success("添加成功！");

        }
        return RespSult.error("添加失败");




        }
    @ApiOperation(value = "删除指定单个信息")
    @DeleteMapping("/{id}")
    public RespSult deleteById(@PathVariable Integer id){

        if (iPositionService.removeById(id)) {
            return RespSult.success("删除成功");

        }
        return RespSult.error("删除失败");
    }
    @ApiOperation(value = "修改职位信息")
    @PutMapping
    public RespSult update(@RequestBody Position position){
        if (iPositionService.updateById(position)) {
            return RespSult.success("更新成功！");

        }
            return RespSult.error("更新失败");
    }
    @ApiOperation(value = "批量删除！")
    @DeleteMapping
    public RespSult deleteByIds(Integer[] ids){
    if (iPositionService.removeByIds(Arrays.asList(ids))){
        return RespSult.success("批量删除成功！");
    }
        return RespSult.error("批量删除失败");
    }


}
